package com.situ.day5;

import java.util.Scanner;

import org.junit.Test;

public class OOPDemo {

	@Test
	public void test1() {
		Student student = new Student();
		student.id = 1;
		student.name = "张三";
		student.age = 23;
		student.className = "Java190703";
		student.study();
		String name = student.name;
		System.out.println(name);
	}
	
	@Test
	public void test2() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的数量：");
		int count = scanner.nextInt();
		Student[] array = new Student[count];
		for (int i = 0; i < array.length; i++) {
			// 每次遍历构造一个学生对象
			Student student = new Student();
			System.out.println("请输入学生编号：");
			int id = scanner.nextInt();
			student.id = id;
			System.out.println("请输入学生姓名：");
			String name = scanner.next();
			student.name = name;
			System.out.println("请输入学生年龄：");
			int age = scanner.nextInt();
			student.age = age;
			System.out.println("请输入学生上课教室：");
			String className = scanner.next();
			student.className = className;
			
			// 将每次遍历生成的student对象放到数组对应下标的位置
			array[i] = student;
		}
		for (int i = 0; i < array.length; i++) {
			// array[i]在等号右表表示：拿出数组下标存放对象
			Student student = array[i];
			System.out.println(student.id);
			System.out.println(student.name);
			System.out.println(student.age);
			System.out.println(student.className);
		}
		
	}
	
}
